package com.strange.mdl.module.mdl.controller.app.activity;

import com.strange.mdl.module.mdl.controller.admin.activity.vo.ActivityPageReqVO;
import com.strange.mdl.module.mdl.service.activity.ActivityUserService;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.strange.mdl.framework.common.pojo.PageParam;
import com.strange.mdl.framework.common.pojo.PageResult;
import com.strange.mdl.framework.common.pojo.CommonResult;
import com.strange.mdl.framework.common.util.object.BeanUtils;
import static com.strange.mdl.framework.common.pojo.CommonResult.success;

import com.strange.mdl.framework.excel.core.util.ExcelUtils;

import com.strange.mdl.framework.apilog.core.annotation.ApiAccessLog;
import static com.strange.mdl.framework.apilog.core.enums.OperateTypeEnum.*;

import com.strange.mdl.module.mdl.controller.app.activity.vo.*;
import com.strange.mdl.module.mdl.dal.dataobject.activity.ActivityDO;
import com.strange.mdl.module.mdl.service.activity.ActivityService;

@Tag(name = "用户 APP - 活动")
@RestController
@RequestMapping("/mdl/appactivity")
@Validated
public class AppActivityController {

    @Resource
    private ActivityService activityService;
//
//    @PostMapping("/create")
//    @Operation(summary = "创建活动")
//    public CommonResult<Long> createActivity(@Valid @RequestBody AppActivitySaveReqVO createReqVO) {
//        return success(activityService.createActivity(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新活动")
//    public CommonResult<Boolean> updateActivity(@Valid @RequestBody AppActivitySaveReqVO updateReqVO) {
//        activityService.updateActivity(updateReqVO);
//        return success(true);
//    }

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private ActivityUserService activityUserService;

    @DeleteMapping("/delete")
    @Operation(summary = "删除活动")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteActivity(@RequestParam("id") Long id) {
        activityService.deleteActivity(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除活动")
    public CommonResult<Boolean> deleteActivityList(@RequestParam("ids") List<Long> ids) {
        activityService.deleteActivityListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @PermitAll
    @Operation(summary = "获得活动")
    @Parameter(name = "id", description = "活动id", required = true, example = "1024")
    @Parameter(name = "userId", description = "用户id", required = true, example = "1024")
    public CommonResult<AppActivityRespVO> getActivity(@RequestParam("id") Long id, @RequestParam("userId") Long userId) {
        AppActivityRespVO activity = activityService.getAppActivity(id, userId);
        return success(activity);
    }

    @GetMapping("/page")
    @PermitAll
    @Operation(summary = "获得活动分页")
    public CommonResult<PageResult<AppActivityRespVO>> getActivityPage(@Valid ActivityPageReqVO pageReqVO) {
        PageResult<AppActivityRespVO> appActivityPage = activityService.getAppActivityPage(pageReqVO);
        return success(appActivityPage);
    }
    @PostMapping("/enterNname")
    @PermitAll
    @Operation(summary = "我要报名")
    public CommonResult<String> enterNname(@RequestBody AppActivityUserSaveReqVO saveReqVO) {
        activityUserService.createAppActivityUser(saveReqVO);
        return success("报名成功");
    }




}